<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>餐饮总账户管理</title>
    <link rel="stylesheet" href="plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="css/comments.css" media="all">
    <style>
        .layui-form-label{
            width: 110px;
        }
        @media screen and (max-width: 450px){
            .layui-form-item .layui-input-inline {
                margin-left: 140px;
            }
        }
    </style>
</head>
<body>
    <div class="maincontainer">
        <div class="layui-card">
            <div class="layui-card-header layuiadmin-card-header-auto">
                <form id="queryForm" class="layui-form" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">餐饮总部名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="name" autocomplete="off" class="layui-input" placeholder="餐饮总部名称" maxlength="20">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">账号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="account" autocomplete="off" class="layui-input" placeholder="账号" maxlength="20">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">审核状态</label>
                            <div class="layui-input-inline">
                                <select name="reviewStatus" lay-filter="reviewStatus">
                                    <option value=""></option>
                                    <option value="0">待审核</option>
                                    <option value="1">审核通过</option>
                                    <option value="2">审核不通过</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">状态</label>
                            <div class="layui-input-inline">
                                <select name="openStatus" lay-filter="openStatus">
                                    <option value=""></option>
                                    <option value="1">启用</option>
                                    <option value="0">禁用</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="button" class="layui-btn"  lay-submit lay-filter="searchBth">查询</button>
                            <button type="reset" class="layui-btn layui-btn-primary reReset" >重置</button>
                        </div>
                    </div>
                </form>
            </div>
            <div class="layui-card-body">
                <table class="layui-hide" id="selectTable" lay-filter="selectTable"></table>
            </div>
        </div>

    </div>
</body>

<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container toolbarDemo">
		<button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
		<button class="layui-btn layui-btn-primary layui-btn-sm" lay-event="export">导出</button>
	</div>
</script>
<script type="text/javascript" src="plugins/layui/layui.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script>
    layui.config({
        base: 'plugins/layui/modules/',
    }).use(['http', 'table', 'form'], function() {
        var http = layui.http,
            table = layui.table,
            form = layui.form;
        var excelList,currPage
		
		$('.reReset').click();

        var reviewStatus = http.getPid('reviewStatus')
        if(reviewStatus){
            $('select[name=reviewStatus]').val(reviewStatus)
            form.render('select')
            tableRender(reviewStatus)
        }else{
            tableRender()
        }

        var selectTable;
        function tableRender(reviewStatus){
            selectTable = http.table({
                elem: '#selectTable',
                url: 'admin/food/manager/listPage',
                method: 'get',
                id: 'selectTable',
                toolbar: '#toolbarDemo',
                where: {
                    reviewStatus: reviewStatus
                },
                done: function(res, curr, count){
                    excelList = res.data;
                    currPage = curr
                },
                cols: [[
                    {title:'序号',type:'numbers',fixed: 'left'}
                    ,{field:'supplierName', title: '餐饮总部名称', align : 'center',
                        templet: function(d){
                            var html = ''
                            html += '<a class="buttoncolor" href="cateringAccountModify.html?id='+d.id+'">'+d.foodCompanyAddress+'</a>'
                            return html
                        }
                    }
                    ,{field:'account', title: '账号', align : 'center'}
                    ,{field:'billTypeStr', title: '结账模式', align : 'center'}
                    ,{field:'billCycle', title: '结账周期', align : 'center',
                        templet: function (d) {
                            var html = ''
                            switch (d.billCycle){
                                case 7:
                                    html = '7天'
                                    break
                                case 15:
                                    html = '15天'
                                    break
                                case 30:
                                    html = '一个月'
                                    break
                                case 90:
                                    html = '一个季度'
                                    break
                                case 182:
                                    html = '半年'
                                    break
                                case 365:
                                    html = '一年'
                                    break
                            }
                            return html
                        }
                    }
                    ,{field:'c', title: '审核状态', align : 'center',
                        templet: function (d) {
                            return d.reviewStatus==0?'<span style="color:#0066FF">待审核</span>':(d.reviewStatus==1?'<span style="color:#000000">审核通过</span>':'<span style="color: #FF0000">审核不通过</span>');
                        }
                    }
                    ,{field:'openStatus', title: '状态', align : 'center',
                        templet: function (d) {
                            return d.openStatus==1?'启用':'禁用';
                        }
                    }
                    ,{field:'', title: '操作', align : 'center',fixed: 'right',width: 330,
                        templet: function (d) {
                            var html = '';
                            if(d.reviewStatus===0){
                                html += '<button type="button" class="layui-btn layui-btn-primary layui-btn-xs" lay-event="checkagree" >审核通过</button>'
                                html += '<button type="button" class="layui-btn layui-btn-primary layui-btn-xs" lay-event="checkdeny" >审核不通过</button>'
                            }
                            html += '<button type="button" class="layui-btn layui-btn-primary layui-btn-xs" lay-event="view" >查看食堂</button>'
                            if(d.openStatus==1){
                                html += '<button type="button" class="layui-btn layui-btn-primary layui-btn-xs" lay-event="state" >禁用</button>'
                            }else{
                                html += '<button type="button" class="layui-btn layui-btn-xs" lay-event="state" >启用</button>'
                            }
                            return html;
                        }
                    }
                ]]
            });
        }
        //查询
        form.on('submit(searchBth)', function (data) {
            let _data = data.field,
				param = _data;
			selectTable.reload({
				page:{curr:1},
				where: param
			})
        })

        table.on('tool(selectTable)', function(obj){
            var data = obj.data;
            if(obj.event=='checkagree'){
                // 审核通过
                http.post('admin/food/manager/agree',{
                    id: data.id
                },function(res){
                    if(res.code == 200){
                        layer.msg('操作成功')
                        table.reload('selectTable');
                    }else{
                        layer.msg(res.msg)
                    }
                })
            }else if(obj.event=='checkdeny'){
                // 审核不通过
                http.post('admin/food/manager/deny',{
                    id: data.id
                },function(res){
                    if(res.code == 200){
                        layer.msg('操作成功')
                        table.reload('selectTable');
                    }else{
                        layer.msg(res.msg)
                    }
                })
            }else if(obj.event=='view'){
                // 查看食堂
                location.href = 'cateringCanteenInfo.html?id=' + data.id
            }else if(obj.event=='state'){
                // 禁用,启用
                http.myOpen({
                    title:'提示',
                    content:'<p style="text-align:center;margin-top:20px;padding: 0 40px">确认要'+(data.openStatus==1?'禁用':'启用')+'餐饮总部信息及该餐饮总部下所有食堂及账号？</p>',
                    area:['300px','170px'],
                    btn:['确定','取消'],
                    btn1:function(index, layero){
                        if(data.openStatus==1){ // 禁用
                            http.post('admin/food/manager/forbidden',{
                                id: data.id
                            },function(res){
                                if(res.code == 200){
                                    layer.msg('操作成功')
                                    layer.close(index)
                                    table.reload('selectTable');
                                }else{
                                    layer.msg(res.msg)
                                }
                            })
                        }else{ // 启用
                            http.post('admin/food/manager/open',{
                                id: data.id
                            },function(res){
                                if(res.code == 200){
                                    layer.msg('操作成功')
                                    layer.close(index)
                                    table.reload('selectTable');
                                }else{
                                    layer.msg(res.msg)
                                }
                            })
                        }  
                    }
                });
            }
        })

        table.on('toolbar(selectTable)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
            var data = checkStatus.data; //获取选中行数据
            if(obj.event=='add'){ 
                // 添加
                location.href = "cateringAccountAdd.html"
            }else if(obj.event=='export'){ // 导出
				var data = excelList; 
				if (data.length == 0) {
					layer.msg('当前页没有可导出的数据');
					return;
                }
                var param = {
                    page: currPage,
                    limit: 10,
                    authentication: localStorage.getItem('xi-can-management-authentication'),
                    openStatus: $('select[name=openStatus]').val(),
                    name: $('input[name=name]').val(),
                    account: $('input[name=account]').val(),
                    reviewStatus: $('select[name=reviewStatus]').val(),
                }
                if (param) {  
                    let paramsArray = [];  
                    //encodeURIComponent  
                    Object.keys(param).forEach(key => paramsArray.push(key + '=' + param[key]))  
                    window.open(TUrl+"admin/food/manager/export?"+paramsArray.join('&'))
                }
			}
        })

    })

</script>
</html>